package com.zhishu.generator;

import cn.hutool.core.io.FileUtil;
import com.zhishu.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * @Author: 止束
 * @Version: 1.0
 * @DateTime: 2025/1/9 14:09
 * @Description:
 */
public class MainGenerator {
    public static void main(String[] args) throws TemplateException, IOException {
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        mainTemplateConfig.setLoop(true);
        mainTemplateConfig.setAuthor("止束");
        mainTemplateConfig.setOutputText("输出");
        doGenerator(mainTemplateConfig);
    }

    public static void doGenerator(Object model) throws TemplateException, IOException {
        String inputRootPath = "D:\\Study\\Code\\Project\\代码生成器平台\\zhishu-generator\\zhishu-generator-demo-projects\\acm-template-pro";
        String outputRootPath = "generated";
        String inputPath;
        String outputPath;
        if (!FileUtil.exist(outputRootPath)) {
            FileUtil.mkdir(outputRootPath);
        }

        //1. 生成动态文件
        //输入路径
        inputPath = new File(inputRootPath, "src/com/zhishu/acm/MainTemplate.java.ftl").getAbsolutePath();
        System.out.println(inputPath);
        //输出路径
        outputPath = new File(outputRootPath, "src/com/zhishu/acm/MainTemplate.java").getAbsolutePath();
        System.out.println(outputPath);
        //生成动态文件
        DynamicGenerator.doGenerate(inputPath, outputPath, model);

        //2. 生成静态文件
        inputPath = new File(inputRootPath, ".gitignore").getAbsolutePath();
        //输出路径
        outputPath = new File(outputRootPath, ".gitignore").getAbsolutePath();
        //生成静态文件
        StaticGenerator.copyFilesByRecursive(inputPath, outputPath);

        inputPath = new File(inputRootPath, "README.md").getAbsolutePath();
        //输出路径
        outputPath = new File(outputRootPath, "README.md").getAbsolutePath();
        //生成静态文件
        StaticGenerator.copyFilesByRecursive(inputPath, outputPath);
    }
}
